from django.db import models
from django.contrib.auth.models import User


class ProjectManage(models.Model):
    project_name = models.CharField(max_length=200, verbose_name='项目名称')
    creator = models.ForeignKey(User, related_name='p_creator', verbose_name='创建人', on_delete=models.CASCADE)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        verbose_name = '项目管理'
        verbose_name_plural = verbose_name
        db_table = 'xt_v_project'

    def __str__(self):
        return self.project_name


class VersionManage(models.Model):
    version_name = models.CharField(max_length=200, verbose_name='版本号')
    upload_date = models.DateField(verbose_name='上载时间')
    creator = models.ForeignKey(User, related_name='v_creator', verbose_name='创建人', on_delete=models.CASCADE)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        verbose_name = '版本管理'
        verbose_name_plural = verbose_name
        db_table = 'xt_v_version'

    def __str__(self):
        return self.version_name


class UploadHistoryManage(models.Model):
    version = models.ForeignKey(VersionManage, related_name='uh_version', on_delete=models.CASCADE, verbose_name='版本号')
    project = models.ForeignKey(ProjectManage, related_name='uh_project', on_delete=models.CASCADE, verbose_name='上载项目')
    night_developer = models.ForeignKey(User, related_name='uh_ndeveloper', on_delete=models.CASCADE, verbose_name='当晚支撑开发')
    night_tester = models.ForeignKey(User, related_name='uh_ntester', on_delete=models.CASCADE, verbose_name='当晚支撑测试')
    night_cmo = models.ForeignKey(User, related_name='uh_cmo', on_delete=models.CASCADE, verbose_name='当晚支撑CMO')
    morning_developer = models.ForeignKey(User, related_name='uh_mdeleloper', on_delete=models.CASCADE, verbose_name='当晚支撑开发')
    morning_tester = models.ForeignKey(User, related_name='uh_tester', on_delete=models.CASCADE, verbose_name='当晚支撑测试')
    night_dedect_no = models.IntegerField(null=True, blank=True, verbose_name='上载当晚问题数', default=0)
    night_defect = models.TextField(max_length=2000, null=True, blank=True, verbose_name='上载当晚问题')
    seven_defect_no = models.IntegerField(null=True, blank=True, verbose_name='上载7天内问题数', default=0)
    severn_defect = models.TextField(max_length=2000, null=True, blank=True, verbose_name='上载7天内问题')
    note = models.TextField(max_length=200, null=True, blank=True, verbose_name='备注')
    creator = models.ForeignKey(User, related_name='uh_creator', verbose_name='创建人', on_delete=models.CASCADE)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        verbose_name = '上载历史管理'
        verbose_name_plural = verbose_name
        db_table = 'xt_v_uploadhistory'

    def __str__(self):
        return self.version.version_name + ' | ' + self.project.project_name


class DefectsManage(models.Model):
    defect_id = models.CharField(max_length=50, primary_key=True, verbose_name='BUG编号')
    project_name = models.CharField(max_length=100, verbose_name='项目名称')
    version_name = models.CharField(max_length=40, verbose_name='版本号')
    module_name = models.CharField(max_length=100, verbose_name='模块名称')
    menu_name = models.CharField(max_length=150, verbose_name='菜单名称')
    description = models.TextField(max_length=1000, verbose_name='菜单名称')
    create_time = models.DateTimeField(verbose_name='创建时间')
    creator = models.CharField(max_length=30, verbose_name='创建人')
    last_modify_user = models.CharField(max_length=30, verbose_name='最后实施修改人')
    last_modify_time = models.DateTimeField(verbose_name='最后实施修改时间')
    requirement = models.CharField(max_length=200, blank=True, null=True, verbose_name='需求单号名称')
    back_times = models.IntegerField(default=0, verbose_name='测试返回测试')
    defect_status = models.CharField(max_length=20, verbose_name='问题单状态')
    close_reason = models.CharField(max_length=20, verbose_name='问题单关闭原因')
    nopass_reason = models.CharField(max_length=20, verbose_name='问题不通过原因')
    defect_reason = models.CharField(max_length=20, verbose_name='问题发生原因')

    class Meta:
        verbose_name = '缺陷管理'
        verbose_name_plural = verbose_name
        db_table = 'xt_v_defect'

    def __str__(self):
        return self.defect_id




